package com.fly.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fly.common.PaginationSupport;
import com.fly.dao.UsersDAO;
import com.fly.model.Users;
import com.fly.model.UsersExample;
import com.fly.service.UsersService;

/**
 * 
 * UsersService 接口实现类
 * 
 * @author 00fly
 * @version [版本号, 2018-09-11]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Service
public class UsersServiceImpl implements UsersService
{
    
    @Autowired
    private UsersDAO usersDAO;
    
    /**
     * 查询全部
     * 
     * @return
     */
    @Override
    public List<Users> queryAll()
    {
        List<Users> list = usersDAO.selectAll();
        return list;
    }
    
    /**
     * 根据条件分页查询
     * 
     * @param criteria 条件对象
     * @param pageNo 页号
     * @param pageSize 页大小
     * @return
     * 
     */
    @SuppressWarnings("unchecked")
    @Override
    public PaginationSupport<Users> queryForPagination(Users criteria, int pageNo, int pageSize)
    {
        return usersDAO.queryPagingEntities(new UsersExample(), pageNo, pageSize);
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see com.fly.service.UsersService#get(java.lang.Long)
     */
    @Override
    public Users get(Long id)
    {
        return usersDAO.selectByPrimaryKey(id.intValue());
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see com.fly.service.UsersService#saveOrUpdate(com.fly.entity.Users)
     */
    @Override
    public void saveOrUpdate(Users users)
    {
        if (users.getId() != null)
        {
            usersDAO.updateByPrimaryKey(users);
        }
        else
        {
            usersDAO.insert(users);
        }
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see com.fly.service.UsersService#delete(java.lang.Long)
     */
    @Override
    public void delete(Long id)
    {
        usersDAO.deleteByPrimaryKey(id.intValue());
    }
}
